-module(mnesiatest).

-export([demoquery/0]).

-record(entry, {id,ip,status}).

mset(Name,Id,Ip) when is_atom(Name);is_number(Name) ->
    X = #(Name){id=Id,ip=Ip}.


demoquery() ->
    mnesia:create_schema([node()]),
    mnesia:start(),
    mnesia:create_table(user, [{attributes, record_info(fields, entry)},{disc_copies, [node()]}]),
    mnesia:create_table(term, [{attributes, record_info(fields, entry)},{disc_copies, [node()]}]),

    mnesia:stop().

example_tables() ->
    [%% The user table
     {user, apple,   20,   2.3},
     {user, orange,  100,  3.8},
     {user, pear,    200,  3.6},
     {user, banana,  420,  4.5},
     {user, potato,  2456, 1.2},
     %% The term table
     {term, apple,   1.5},
     {term, orange,  2.4},
     {term, pear,    2.2},
     {term, banana,  1.5},
     {term, potato,  0.6}
    ].

add_user_item(Name, Quantity, Term) ->
    Row = #user{item=Name, quantity=Quantity, term=Term},
    F = fun() ->
		mnesia:write(Row)
	end,
    mnesia:transaction(F).
